<template>
  <div class="info" v-loading="loading">
    <div class="card_con search_data mb15">
      <el-row class="mb15">
        <el-col :span="8" class="pr40">
          <div class="fz13 mb10">关键搜索：</div>
          <el-input
            v-model="keyName"
            placeholder="请输入商品id/商品名/店铺名"
          ></el-input>
        </el-col>
        <el-col :span="8" class="pr40">
          <div class="fz13 mb10">时间</div>
          <el-date-picker
            value-format="yyyy-MM-dd HH:mm:ss"
            v-model="time"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          >
          </el-date-picker>
        </el-col>
        <el-col :span="8" class="pr40">
          <div class="fz13 mb10">商品分类：</div>
          <el-cascader
            @change="cascaderChange"
            :props="optionProps"
            :options="typeArr"
            v-model="typeId"
          >
            <template slot-scope="{ data }">
              <span>{{ data.name }}</span>
            </template>
          </el-cascader>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="8" class="pr40">
          <div class="fz13 mb10">状态：</div>
          <el-select v-model="shopStateId" placeholder="请选择">
            <el-option
              v-for="item in shopStateArr"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </el-col>
        <el-col :span="8" class="pr40">
          <div class="fz13 mb10">商品类型：</div>
          <el-select clearable v-model="shopLineStateId" placeholder="请选择">
            <el-option
              v-for="item in shopLineStateArr"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </el-col>
        <el-col :span="4">
          <div class="fz13 mb10">&nbsp;</div>
          <el-button type="primary" @click="handleSearch">查询</el-button>
        </el-col>
      </el-row>
    </div>
    <div class="card_con">
      <el-table
        border
        :data="tableData"
        :header-cell-style="{
          'text-align': 'center',
        }"
        :cell-style="{ 'text-align': 'center' }"
        style="width: 100%"
        highlight-current-row
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" min-width="5%"> </el-table-column>
        <el-table-column prop="id" label="id" min-width="20%">
        </el-table-column>
        <el-table-column
          show-overflow-tooltip="true"
          prop="name"
          label="商品名"
          min-width="20%"
        >
        </el-table-column>
        <el-table-column prop="cate_text" label="商品分类" min-width="15%">
        </el-table-column>
        <el-table-column label="商品图" min-width="15%">
          <template slot-scope="scope">
            <div class="slt">
              <el-popover placement="right" width="200" trigger="hover">
                <img class="tbImg1" :src="scope.row.thumb.src" alt="" />
                <img
                  class="tbImg"
                  slot="reference"
                  :src="scope.row.thumb.src"
                  alt=""
                />
              </el-popover>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="price" label="现价" min-width="15%">
        </el-table-column>
        <el-table-column prop="sale" label="销量" min-width="10%">
        </el-table-column>
        <!-- <el-table-column prop="is_online" label="商品类型" min-width="10%">
        </el-table-column> -->
        <!-- <el-table-column prop="status" label="状态" min-width="10%">
          <template slot-scope="scope">
            <div>{{ scope.row.status }}</div>
          </template>
        </el-table-column> -->
        <el-table-column prop="create_time" label="创建时间" min-width="30%">
        </el-table-column>
      </el-table>
      <div class="pagination">
        <Pagination :page="page" @onCurrentChange="handleCurrentChange" />
      </div>
    </div>
  </div>
</template>

<script>
import Pagination from "@/components/Pagination.vue";
import { allShopList, shopCategory } from "@/api/mall_management";
export default {
  components: { Pagination },
  data() {
    return {
      loading: true,
      keyName: "",
      time: "",
      tableData: [],
      selectionKeys: [], //表格选择数据
      typeArr: [],
      typeId: [],
      optionProps: {
        value: "id",
        label: "name",
        children: "children",
        checkStrictly: true,
      },
      shopStateArr: [
        { id: "0", name: "全部" },
        { id: "1", name: "上架" },
        { id: "2", name: "下架" },
      ],
      shopStateId: "0",
      shopLineStateArr: [
        { id: "1", name: "线上" },
        { id: "0", name: "线下" },
      ],
      shopLineStateId: "0",
      page: {
        total: 0,
        pageNum: 1, // 当前页数
        pageSize: 10, // 每页的条数
      },
      remarks: "", //开关备注输入
      remarks_state: "", //开关参数
      dialogVisible: false,
      title: "",
      detailDialog: false,
      up_down_dialog: false,
      rowId: "", //当前行id
      rowData: "",
    };
  },
  methods: {
    //商品列表
    async allShopList() {
      const { data, err } = await allShopList({
        page: this.page.pageNum,
        key: this.keyName,
        st_s: this.time ? this.time[0].valueOf() : 0,
        st_e: this.time ? this.time[1].valueOf() : 0,
        status: this.shopStateId,
        is_online: this.shopLineStateId,
        type_id: this.typeId.join(","),
      });
      if (err === 0) {
        this.loading = false;
        //正确
        this.tableData = data.data;
        this.page.total = data.total;
        this.page.pageNum = data.current_page;
        this.page.pageSize = data.per_page;
      }
    },
    //商品类型
    async shopCategory() {
      const { data, err } = await shopCategory({});
      if (err === 0) {
        this.typeArr = data;
        this.allShopList();
      }
    },
    //查询
    handleSearch() {
      this.loading = true;
      this.page.pageNum = 1;
      this.allShopList();
    },

    //表格选择数据
    handleSelectionChange(rows) {
      this.selectionKeys = rows.map((item) => item.id);
      this.rowId = this.selectionKeys.join(",");
    },
    // 当前页: ${val}
    handleCurrentChange(val) {
      this.page.pageNum = val;
      this.loading = true;
      this.allShopList();
    },
    //开关编辑
    changeSwitch(row) {
      //0上架 1   1下架 2
      this.up_down_dialog = true;
      this.rowId = row.id;
      console.log(row.status);
      this.remarks_state = row.status;
      //   if (row.status === 1) {
      //     //1上架 操作下架
      //     this.remarks_state = 2;
      //   } else {
      //     //2下架  操作上架
      //     this.remarks_state = 1;
      //   }
      //
    },
    //开关备注提交
    handleRemark() {
      if (this.remarks === "") {
        this.$message({
          showClose: true,
          message: "请输入备注",
          type: "warning",
        });
      } else {
        this.up_down_dialog = false;
        this.switchRemark();
      }
    },
    //开关弹窗关闭
    remarkClose() {
      this.up_down_dialog = false;
      this.remarks = "";
      this.allShopList();
    },
  },
  created() {
    this.shopCategory();
  },
};
</script>

<style lang="scss" scoped>
@import "@/style/index.scss";
.info {
  .title {
    font-size: 16px;
    margin-bottom: 13px;
  }
}
.pagination {
  display: flex;
  justify-content: flex-end;
  padding-top: 10px;
}
.el-select {
  width: 100%;
}

.tb {
  background-color: #fff;
  padding: 20px;
  box-sizing: border-box;
}
.row {
  display: flex;
  border-radius: 2px;
  //   border: 1px solid #ccc;
  .l {
    padding: 8px 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid #ccc;
    font-size: 13px;
    i {
      margin-right: 6px;
      font-size: 13px;
    }
    &:hover {
      cursor: pointer;
    }
  }
  .l:nth-child(1) {
    border-right: 0;
  }
}

/deep/.el-table .el-table__cell {
  padding: 10px 0;
}
.search_data {
  /deep/.el-input__inner {
    height: 36px;
    line-height: 36px;
    font-size: 13px;
  }
}

.beizhu {
  padding: 0 20px 50px 20px;
  box-sizing: border-box;
  .bz {
    margin-bottom: 10px;
    margin-top: 20px;
  }
  .btn {
    margin-top: 20px;
    .el-button {
      width: 100%;
    }
  }
}
</style>
